
const path = require('path');
const webpack = require('webpack');
const cleanWebpackPlugin = require('clean-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');
const miniCssExtractPlugin = require('mini-css-extract-plugin');
const glob = require('glob');

const webpackConfig =  {
	entry:{
		a:'./src/front/index.js',
		b:'./src/manage/index.js'
	},
	output:{
        path:path.resolve(__dirname, './dist/'),
        filename:'[name].[chunkhash:6].js'
    },
	devServer:{
		host:'localhost',
		port:8080,
		open:true
	},
	plugins:[
		new cleanWebpackPlugin(),
		new htmlWebpackPlugin({
            title:'i旅行',
            template:'./public/index.html',
            filename:'index.html',
            chunks:['a'],   //引入对应的js，需要用到chunks
        }),
        new htmlWebpackPlugin({
            title:'b页面',
            template:'./public/index.html',
            filename:'manage.html',
            chunks:['b'],
        }),
        new webpack.ProvidePlugin({
	      $: 'n-zepto'
	    })
	],
	module:{
		rules:[
			{
				test:/\.js?$/,
                exclude:/node_modules/,
                loader:'babel-loader',
                query:{
                    presets:['es2015','react']
                }
			},
			{
				test:/\.less$/,
				use:[
					{
						loader:miniCssExtractPlugin.loader,
						options:{
							publicPath:'../'
						}
					},
					'css-loader',
					'less-loader'
				]
			},
			{
				test:/\.(jpg|png|gif)$/,
				use:[
					{
						loader:'url-loader',
						options:{
							limit:5*1024,
							outputPath:'images'
						}
					}
				]
			},
			{
				test:/\.css/,
				use:['style-loader','css-loader']
			},
			{
				test: require.resolve(path.join(__dirname, 'src/js/lib/flexible.js')),
				loader: "expose-loader?flexible"
			},
			/*{
		      test: require.resolve('zepto'),
		      loader: 'exports-loader?window.Zepto!script-loader'
		    }*/
			
		]
	}
}

module.exports = webpackConfig;